﻿using DataWorks_Tools.MappModals;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace DataWorks_Tools.SpikeDetails
{
    public class RemoveSpikeProcess
    {
        /// <summary>
        /// 整个流程只是处理一列的数据
        /// </summary>
        /// <param name="signal"></param>
        /// <param name="blockLengthMean"></param>
        /// <param name="blockLengthVariance"></param>
        /// <param name="percentage"></param>
        /// <param name="ratio"></param>
        /// <param name="spikecolumn"></param>
        /// <param name="pointcounts"></param>
        /// <returns></returns>
        public static List<SpikeinFileClass>? SpikeRemovalProcess(List<double> signal, int blockLengthMean, int blockLengthVariance, double percentage, double ratio, int spikecolumn, int pointcounts, List<int> csvsrowcount)
        {
            var smooth = Spike_Removal.MeanSignalCal(signal, blockLengthMean);
            var roughr = Spike_Removal.CreateRoughSignal(signal, smooth);
            var mrr = Spike_Removal.MRiCal(roughr, blockLengthVariance);
            var variance = Spike_Removal.VarianceSignalCal(roughr, mrr, blockLengthVariance);
            //检测spike并获取spike的序号
            var spikeindex = Spike_Removal.DetectSpikes(variance, percentage);
            var groupspikeindex = Spike_Removal.GroupConsecutiveNumbers(spikeindex);
            var mergegroup = Spike_Removal.MergeConsecutiveGroups(groupspikeindex);
            var spikeexactindex = Spike_Removal.GetAccurateSpikeIndex(signal, mergegroup, pointcounts);
            var interceptvalue = Spike_Removal.GetratioFilterValue(signal, spikeexactindex, ratio);
            var result= Spike_Removal.GetspikeinFileClasses(spikeexactindex, spikecolumn,interceptvalue, csvsrowcount);
            return result;
        }
    }
}
